<template>
  <div class="container">
    <div>
      <el-row :gutter="20">
        <el-col :span="6">
          <el-form ref="form" :model="form">
            <el-form-item label="开始日期：">
              <el-date-picker
                v-model="form.StartDate"
                type="date"
                placeholder="选择日期"
                value-format="yyyy-MM-dd"
              ></el-date-picker>
            </el-form-item>
          </el-form>
        </el-col>
        <el-col :span="6">
          <el-form ref="form" :model="form">
            <el-form-item label="结束日期：">
              <el-date-picker
                v-model="form.EndDate"
                type="date"
                placeholder="选择日期"
                value-format="yyyy-MM-dd"
              ></el-date-picker>
            </el-form-item>
          </el-form>
        </el-col>
        <el-col :span="6">
          <el-form ref="form" :model="form" style="float:left">
            <el-button size="mini" type="primary" @click="getlistdata">查 询</el-button>
            <el-button size="mini" type="success" @click="exportExcel">导 出</el-button>
          </el-form>
        </el-col>
      </el-row>
    </div>
    <el-table v-loading="loading" :data="tableData.slice((currentPage-1)*pageSize,currentPage*pageSize)" highlight-current-row>
      <el-table-column prop="车牌号" label="车牌号" align="center" width="200"></el-table-column>
      <el-table-column prop="车辆类型" label="车辆类型" align="center"></el-table-column>
      <el-table-column prop="违规开始时间" label="违规开始时间" align="center"></el-table-column>
      <el-table-column prop="违规结束时间" label="违规结束时间" align="center"></el-table-column>
      <el-table-column prop="持续时长" label="持续时长" align="center" width="170"></el-table-column>
      <!-- <el-table-column label="操作" width="100">
        <template slot-scope="scope">
          <el-button type="text" icon="el-icon-info" @click="handleEdit(scope.$index, scope.row)">详情</el-button>
        </template>
      </el-table-column>-->
    </el-table>
    <div class="pagination">
      <el-pagination
        background
        layout="total, sizes, prev, pager, next, jumper"
        :current-page="currentPage"
        :page-size="pageSize"
        :total="tableData.length"
        @size-change="handleSizeChange"
        @current-change="handlePageChange"
      ></el-pagination>
    </div>
  </div>
</template>
<script>
import '@/assets/css/common.css'
import { formatDate } from '@/common/js/date.js'
import export2Excel from '@/utils/exportExcel/index.js'
export default {
  data () {
    return {
      currentPage: 1, //初始页
      pageSize: 10,    //    每页的数据
      loading: false,
      form: {
        StartDate: formatDate(new Date(new Date().getTime() - 3600 * 1000 * 24), 'yyyy-MM-dd'),
        EndDate: formatDate(new Date(new Date().getTime() + 3600 * 1000 * 24), 'yyyy-MM-dd'),
      },
      // teamList: [{ "CLIENT_NAME": "机扫车" }, { "CLIENT_NAME": "垃圾车" }],
      // teamValue: '机扫车',
      tableData: [],
      originalData: []
    }
  },
  created () {
    this.getlistdata()
  },
  methods: {
    async getlistdata () {
      this.currentPage = 1;
      this.loading = true
      var url = 'Vehicle/GetVehicleOutInfo?StartDate=' + this.form.StartDate + '&EndDate=' + this.form.EndDate + '&ClientNO=' + localStorage.getItem('CLIENT_NO')
      const { data } = await this.$Http.get(url)
      console.log(data)
      this.tableData = data
      this.loading = false
    },
    // 导出Excel
    exportExcel () {
      //   <el-table-column prop="车牌号" label="车牌号" align="center" width="200"></el-table-column>
      // <el-table-column prop="车辆类型" label="车辆类型" align="center"></el-table-column>
      // <el-table-column prop="违规开始时间" label="违规开始时间" align="center"></el-table-column>
      // <el-table-column prop="违规结束时间" label="违规结束时间" align="center"></el-table-column>
      // <el-table-column prop="持续时长" label="持续时长" align="center" width="170"></el-table-column>
      // <el-table-column prop="结束出行时间" label="结束出行时间" align="center" width="170"></el-table-column>
      // <el-table-column prop="出行总时长分钟" label="出行总时长（分钟）" align="center"></el-table-column>
      // <el-table-column prop="出行总里程米" label="出行总里程（米）" align="center"></el-table-column>
      // <el-table-column prop="平均速度迈" label="平均速度（迈）" align="center"></el-table-column>
      // <el-table-column prop="作业总时长分钟" label="作业总时长（分钟）" align="center"></el-table-column>
      // <el-table-column prop="作业总里程米" label="作业总里程（米）" align="center"></el-table-column>
      let excelName = '车辆越界统计'
      const tHeader = ['车牌号', '车辆类型', '违规开始时间','违规结束时间', '持续时长']
      const filterVal = ['车牌号', '车辆类型', '违规开始时间','违规结束时间', '持续时长']
      export2Excel(tHeader, filterVal, this.tableData, excelName)
    },
    //详情
    handleEdit (index, row) {
      //   this.idx = index;
      //   this.form = row;
      //   this.editVisible = true;
    },
    // 分页导航
    handlePageChange (currentPage) {
      this.currentPage = currentPage;
      // console.log(this.currentPage)
      // this.$set(this.query, 'pageIndex', val);
      // this.getData();
    },
    handleSizeChange (size) {
      this.pageSize = size;
      console.log(this.pageSize)
    }
  }
}
</script>
<style>
.content {
  overflow-y: scroll;
}
.el-col-6 {
  min-width: 400px;
  min-height: 50px;
}
.el-table th {
  height: 40px;
}
</style>